package leetcode.mapCode.week1.leetcode_797;

import java.util.ArrayList;
import java.util.List;

class Solution {

    private List<List<Integer>> ans = new ArrayList<>();
    private List<Integer> path = new ArrayList<>();
    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
        path.add(0);
        dfs(graph,0,graph.length-1);
        return ans;
    }
    private void dfs(int [][] graph , int x ,int y){
        if (x==y){
            ans.add(new ArrayList<>(path));
            return;
        }
        for (int   i : graph[x]){
            path.add(i);
            dfs(graph,i ,y);
            path.remove(path.size()-1);
        }
    }
}